    package com.edu.bhu.admin.controller.admin;

import java.util.List;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.edu.bhu.common.annotation.Log;
import com.edu.bhu.common.enums.BusinessType;
import com.edu.bhu.admin.domain.CosType;
import com.edu.bhu.admin.service.ICosTypeService;
import com.edu.bhu.common.core.controller.BaseController;
import com.edu.bhu.common.core.domain.AjaxResult;
import com.edu.bhu.common.utils.poi.ExcelUtil;
import com.edu.bhu.common.core.page.TableDataInfo;

/**
 * 商品种类Controller
 * 
 * @author wangjinao
 * @date 2022-03-17
 */
@Controller
@RequestMapping("/admin/type")
public class CosTypeController extends BaseController
{
    private String prefix = "admin/type";

    @Autowired
    private ICosTypeService cosTypeService;

    @RequiresPermissions("admin:type:view")
    @GetMapping()
    public String type()
    {
        return prefix + "/type";
    }

    /**
     * 查询商品种类列表
     */
    @RequiresPermissions("admin:type:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(CosType cosType)
    {
        startPage();
        List<CosType> list = cosTypeService.selectCosTypeList(cosType);
        return getDataTable(list);
    }

    /**
     * 查询商品种类列表
     */
    @RequiresPermissions("admin:type:list")
    @PostMapping("/listNotPage")
    @ResponseBody
    public TableDataInfo listNotPage(CosType cosType)
    {
        List<CosType> list = cosTypeService.selectCosTypeList(cosType);
        return getDataTable(list);
    }

    /**
     * 导出商品种类列表
     */
    @RequiresPermissions("admin:type:export")
    @Log(title = "商品种类", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(CosType cosType)
    {
        List<CosType> list = cosTypeService.selectCosTypeList(cosType);
        ExcelUtil<CosType> util = new ExcelUtil<CosType>(CosType.class);
        return util.exportExcel(list, "商品种类数据");
    }

    /**
     * 新增商品种类
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存商品种类
     */
    @RequiresPermissions("admin:type:add")
    @Log(title = "商品种类", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(CosType cosType)
    {
        return toAjax(cosTypeService.insertCosType(cosType));
    }

    /**
     * 修改商品种类
     */
    @RequiresPermissions("admin:type:edit")
    @GetMapping("/edit/{typeId}")
    public String edit(@PathVariable("typeId") Long typeId, ModelMap mmap)
    {
        CosType cosType = cosTypeService.selectCosTypeByTypeId(typeId);
        mmap.put("cosType", cosType);
        return prefix + "/edit";
    }

    /**
     * 修改保存商品种类
     */
    @RequiresPermissions("admin:type:edit")
    @Log(title = "商品种类", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(CosType cosType)
    {
        return toAjax(cosTypeService.updateCosType(cosType));
    }

    /**
     * 删除商品种类
     */
    @RequiresPermissions("admin:type:remove")
    @Log(title = "商品种类", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(cosTypeService.deleteCosTypeByTypeIds(ids));
    }
}
